{include file="head" title="单页修改" /}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">单页修改</div>
        <div class="layui-card-body" style="padding: 15px;">
            <form id="form" class="layui-form" action="" style="width:80%;">
                <input type="hidden" name="id" value="{:$s->id}">
                <div class="layui-form-item">
                    <label class="layui-form-label">标题<span class="form_require">*</span></label>
                    <div class="layui-input-block w50">
                        <input type="text" name="title" value="{:$s->title}" lay-verify="required" autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">副标题</label>
                    <div class="layui-input-block w50">
                        <input type="text" name="subtitle" value="{:$s->subtitle}"  placeholder="请输入副标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">别名</label>
                    <div class="layui-input-block w50">
                        <input type="text" name="alias" value="{:$s->alias}" lay-verify="required" autocomplete="off" placeholder="请输入别名" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block w50">
                        <textarea placeholder="请输入描述" name='description'  class="layui-textarea">{:$s->description}</textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">作者</label>
                        <div class="layui-input-inline">
                            <input type="text" name="author" value='{:$s->author}' autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">关键字</label>
                        <div class="layui-input-inline">
                            <input type="text" name="keywords" value='{:$s->keywords}' autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>

                <fieldset class="layui-elem-field">
                    <legend>缩略图</legend>
                    <div class="layui-field-box ">
                        <div class="layui-upload">
                            <button type="button" class="layui-btn" id="test1">选择图片</button>
                            <input type="hidden" id="pic" name="pic" value="{$s->pic}" />
                            <div class="layui-upload-list">
                                <img class="layui-upload-img" id="demo1" style="width:150px" src="{:$s->pic}">
                                <p id="demoText"></p>
                            </div>
                        </div>
                    </div>
                </fieldset>
                <style>
                    .upload_imgs{
                        width:150px;max-height:180px
                    }
                </style>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-inline">
                            <input type="hidden" name="date" value='{:$s->date}' id="date" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">文章详情</label>
                    <div class="layui-input-block">
                        <textarea class="" name="content" style=" height:350px;"  id="content">{:$s->content}</textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        {:get_radio('1',public_status(),'status')}
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
                        <button type="button" class="layui-btn layui-btn-primary" onclick="javascript:history.back(-1)">返回</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    layui.config({
        base: '{$Think.const.admin_tpl}/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'upload', 'laydate'], function () {
        var $ = layui.$
                , layer = layui.layer
                , laydate = layui.laydate
                , upload = layui.upload
                , form = layui.form;

        //缩略图
        var uploadInst = upload.render({
            elem: '#test1'
            , url: '/admin/files/upload_post/'
            , field: 'Filedata'
            , exts: 'jpg|png|gif'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                $("#pic").val(res.file);
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

        //创建百度编辑器
        var ue = UE.getEditor('content');

        $("body").on("click", ".images_close", function () {
            $(this).parent('.blockquote_box').remove();
        });

        /* 监听提交 */

        form.on('submit(sub)', function (data) {
            console.log($("#form").serialize());
            $.ajax({
                url: "/admin/singles/singles_submit/",
                type: 'post',
                data: $("#form").serialize(),
                dataType: 'json',
                success: function (data) {
                    if (data.status == 1)
                    {
                        layer.confirm(data.msg + '请选择？', {
                            btn: ['继续添加', '返回列表'] //按钮
                        }, function () {
                            location.href = '/admin/singles/add.html';
                        }, function () {
                            location.href = '/admin/singles/index.html';
                        });
                    }
                    else
                    {
                        layer.msg(data.msg);
                    }
                },
                error: function (msg) {
                    alert(" 数据保存失败！" + msg);
                }
            });

            return false;
        });
    });
</script>
{include file="foot" /}
